#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 100010;
int n, m, L, V, ans1, ans2 = 0;
int dtr[N], cnt[N][N], over[N] = {0};
	
struct car{
	int d;
	int v0;
	int a;
}c[N];

int main() {
	freopen("detect.in", "r", stdin);
	freopen("detect.out", "w", stdout);
	int T;
	scanf("%d", &T);
	while (T -- ) {
		ans1 = 0, ans2 = 0;
		memset(dtr, 0, sizeof(dtr));
		memset(cnt, 0, sizeof(cnt));
		memset(over, 0, sizeof(over));

		// cnt[i][j] for  
		scanf("%d%d%d%d", &n, &m, &L, &V);
		bool spe = false;
		for (int i = 1; i <= n; i ++ )
			scanf("%d%d%d", &c[i].d, &c[i].v0, &c[i].a);
		for (int i = 1; i <= m; i ++ )
			scanf("%d", &dtr[i]);
		for (int i = 1; i <= n; i ++ ) {		// i in car, ranging from 1
			int d = c[i].d;
			int v0 = c[i].v0;
			int a = c[i].a;
			
			for (int j = 1; j <= m; j ++ ) {	// j in detector, ranging from 1
				int x = dtr[i];
				if (x < d) {
					double v = sqrt((double)v0*(double)v0 + 2*(double)a*(double)(d - x));
					if (v > (double)V) {cnt[i][j] = true; cnt[i][0] ++ ; cnt[0][j] ++ ; over[i] = 1;}
				}
			}
			if (over[i]) ans1 ++ ;
			if (cnt[i][0] == 1) spe = true;
		}
		if(spe) {printf("%d %d\n", ans1, ans2); continue;}
		
		for (int i = 1; i <= m; i ++ ) {
			if (cnt[0][i] == n) {ans2 = m - 1; break;}
			if (cnt[0][i]) {
				for (int j = 1; j <= n; j ++ ) {
					if (!over[i]) continue;
					ans2 = n - 46;
				}
			}
			
		}
		
		printf("%d %d\n", ans1, ans2);
	}
	
	
	return 0;
}

